#include "SkyBox.h"

SkyBox::SkyBox(IDirect3DDevice9 *d3ddev)
{
	D3DCOLOR BlockColor;
	BlockColor = D3DCOLOR_ARGB(0xff, 500, 0, 0);
	CUSTOMVERTEX vertices[] =
	{
		{ -sizeX-4, -sizeY+57 , -sizeZ+45, BlockColor, 1.0f, 1.0f, },  //1
		{ -sizeX-4, sizeY+57, -sizeZ+45, BlockColor, 0.0f, 0.0f, },  //2
		{ sizeX-4, sizeY+57, -sizeZ+45, BlockColor, 1.0f, 0.0f, },   //3
		{ sizeX-4, -sizeY+57, -sizeZ+45, BlockColor, 1.0f, 1.0f, },  //4
		{ -sizeX-4, -sizeY+57, sizeZ+45, BlockColor, 1.0f, 1.0f, },  //5
		{ sizeX-4, -sizeY+57, sizeZ+45, BlockColor, 1.0f, 0.0f, },	 //6
		{ sizeX-4, sizeY+57, sizeZ+45, BlockColor, 0.0f, 0.0f, },    //7
		{ -sizeX-4, sizeY+57, sizeZ+45, BlockColor, 0.0f, 1.0f, },	 //8
	};

	d3ddev->CreateVertexBuffer(sizeof(vertices),
		D3DUSAGE_WRITEONLY,
		CUSTOMFVF,
		D3DPOOL_MANAGED,
		&m_vbuffer,
		NULL);

	sizeX = 48;
	sizeY = 1;
	sizeZ = 48;
	
	CUSTOMVERTEX vertices1[] =
	{
		{ -sizeX - 4, -sizeY + 57, -sizeZ + 45, BlockColor, 1.0f, 1.0f, },  //1
		{ -sizeX - 4, sizeY + 57, -sizeZ + 45, BlockColor, 0.0f, 0.0f, },  //2
		{ sizeX - 4, sizeY + 57, -sizeZ + 45, BlockColor, 1.0f, 0.0f, },   //3
		{ sizeX - 4, -sizeY + 57, -sizeZ + 45, BlockColor, 1.0f, 1.0f, },  //4
		{ -sizeX - 4, -sizeY + 57, sizeZ + 45, BlockColor, 1.0f, 1.0f, },  //5
		{ sizeX - 4, -sizeY + 57, sizeZ + 45, BlockColor, 1.0f, 0.0f, },	 //6
		{ sizeX - 4, sizeY + 57, sizeZ + 45, BlockColor, 0.0f, 0.0f, },    //7
		{ -sizeX - 4, sizeY + 57, sizeZ + 45, BlockColor, 0.0f, 1.0f, },	 //8
	};

	d3ddev->CreateVertexBuffer(sizeof(vertices1),
		D3DUSAGE_WRITEONLY,
		CUSTOMFVF,
		D3DPOOL_MANAGED,
		&m_vbuffer,
		NULL);



	VOID* pVoid;

	m_vbuffer->Lock(0, 0, (void**)&pVoid, 0);
	memcpy(pVoid, vertices, sizeof(vertices));
	m_vbuffer->Unlock();

	short indices[] =
	{
		0, 1, 2,
		2, 3, 0,
		4, 5, 6,
		6, 7, 4,
		0, 3, 5,
		5, 4, 0,
		3, 2, 6,
		6, 5, 3,
		2, 1, 7,
		7, 6, 2,
		1, 0, 4,
		4, 7, 1
	};

	d3ddev->CreateIndexBuffer(sizeof(indices),
		D3DUSAGE_WRITEONLY,
		D3DFMT_INDEX16,
		D3DPOOL_MANAGED,
		&m_ibuffer,
		NULL);

	m_ibuffer->Lock(0, 0, (void**)&pVoid, 0);
	memcpy(pVoid, indices, sizeof(indices));
	m_ibuffer->Unlock();
}


SkyBox::~SkyBox()
{
}
